package com.javasm.transfer.goods;

import com.javasm.domin.entity.goods.*;
import com.javasm.domin.vo.goods.GiftsToGoodsVo;
import com.javasm.mapper.goods.BaseBrandMapper;
import com.javasm.mapper.goods.BaseTypeMapper;
import com.javasm.mapper.goods.ColorMapper;
import com.javasm.mapper.goods.ProductMapper;
import com.javasm.transfer.base.BaseTransfer;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author：Drd
 * @Version：1.0
 * @Date：2022/1/17-20:32
 * @Since:jdk1.8
 * @Description:
 */
@Component
@RequiredArgsConstructor
public class GiftsToGoodsTransfer extends BaseTransfer<GiftsToGoods, GiftsToGoodsVo> {

    private final ColorMapper colorMapper;

    private final BaseTypeMapper baseTypeMapper;

    private final BaseBrandMapper baseBrandMapper;

    private final ProductMapper productMapper;

    public List<GiftsToGoodsVo> setInfo(List<GiftsToGoods> list) {
        List<GiftsToGoodsVo> giftsToGoodsVos = super.toVO(list);
        for (int i = 0; i < giftsToGoodsVos.size(); i++) {
            GiftsToGoods giftsToGoods = list.get(i);
            //对颜色进行赋值
            Color color = colorMapper.selectById(giftsToGoods.getGiftsColor());
            GiftsToGoodsVo giftsToGoodsVo = giftsToGoodsVos.get(i);
            giftsToGoodsVo.setGiftsColor(color == null ? "" : color.getColorName());
//对品牌进行赋值
            BaseBrand baseBrand = baseBrandMapper.selectById(giftsToGoods.getBrandId());
            giftsToGoodsVo.setBrandId(baseBrand == null ? "" : baseBrand.getBrandName());

//对产品信息进行赋值
            Product product = productMapper.selectById(giftsToGoods.getProductId());
            giftsToGoodsVo.setProductId(product == null ? "" : product.getProductName());

            if (giftsToGoods.getApproveStatus() == null) {
                giftsToGoodsVo.setApproveStatus("未知");
            } else if (giftsToGoods.getApproveStatus() == 0) {
                giftsToGoodsVo.setApproveStatus("待审核");
            } else if (giftsToGoods.getApproveStatus() == 1) {
                giftsToGoodsVo.setApproveStatus("已审核");
            } else if (giftsToGoods.getApproveStatus() == 2) {
                giftsToGoodsVo.setApproveStatus("审核不通过");
            } else {
                giftsToGoodsVo.setApproveStatus("未知");
            }
        }
        return giftsToGoodsVos;
    }



}
